#include "Timer_Test.h"

#include "misc/Timer.h"
#include "misc/Event.h"
#include <iostream>
/*********************************************************/
std::string TimerTest::name()
{
	return("Timer");
}
/*********************************************************/
bool TimerTest::runUnitTests()
{
	bool result = true;

	if ( !TimerCreationTest() ) result = false;
	if ( !persistanceTest() )  result = false;

	return( result ) ;
}
/*********************************************************/
bool TimerTest::persistanceTest()
{
	std::cout << "Running: persistanceTest()";
	std::cout.flush();

	Event* ev = Event::Instance("TESTTIMER");
	Timer testTimer("TESTTIMER", 2, true);
	
	for ( unsigned int i=0; i<2; i++ ) {
		if ( !ev->tryWait(2500) ) {
			std::cout << "... failed!" << std::endl;
			return false;
		}
	}

	std::cout << "... success!" << std::endl;
	return true;
}
/*********************************************************/
bool TimerTest::TimerCreationTest()
{
	std::cout << "Running: TimerCreationTest()";
	std::cout.flush();

	Event*	ev = Event::Instance("TESTTIMER");
	Timer	testTimer("TESTTIMER", 2, false);
	
	if ( !ev->tryWait(2500) ) {		// Wait at most 2.5 seconds for the timer to activate the event
		std::cout << "... failed!" << std::endl;
		return false;
	}
	
	std::cout << "... success!" << std::endl;
	return true;
}
/*********************************************************/
